<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>员工信息管理系统 - 员工列表</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
    <div class="header-content">
        <h1>员工信息管理系统</h1>
        <div class="user-info">
            <span>欢迎您，${user.username}</span>
            <a href="${pageContext.request.contextPath}/logout" class="logout-btn">退出登录</a>
        </div>
    </div>
</header>

<nav>
    <ul>
        <li><a href="${pageContext.request.contextPath}/dashboard.jsp">首页</a></li>
        <li><a href="${pageContext.request.contextPath}/employee" class="active">员工管理</a></li>
    </ul>
</nav>

<main>
    <div class="content">
        <div class="content-header">
            <h2>员工列表</h2>
            <a href="${pageContext.request.contextPath}/employee/add" class="btn-add">添加员工</a>
        </div>

        <!-- 搜索表单 -->
        <div class="search-form">
            <form action="${pageContext.request.contextPath}/employee" method="get">
                <div class="form-group">
                    <label for="name">姓名</label>
                    <input type="text" id="name" name="name" value="${queryDTO.name}">
                </div>
                <div class="form-group">
                    <label for="department">部门</label>
                    <input type="text" id="department" name="department" value="${queryDTO.department}">
                </div>
                <div class="form-group">
                    <label for="position">职位</label>
                    <input type="text" id="position" name="position" value="${queryDTO.position}">
                </div>
                <button type="submit" class="btn-search">搜索</button>
                <a href="${pageContext.request.contextPath}/employee" class="btn-reset">重置</a>
            </form>
        </div>

        <!-- 员工列表 -->
        <table class="employee-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>部门</th>
                <th>职位</th>
                <th>薪资</th>
                <th>入职日期</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageDTO.list}" var="emp">
                <tr>
                    <td>${emp.id}</td>
                    <td>${emp.name}</td>
                    <td>${emp.department}</td>
                    <td>${emp.position}</td>
                    <td><fmt:formatNumber value="${emp.salary}" type="number" pattern="###,###.00"/></td>
                    <td><fmt:formatDate value="${emp.hireDate}" pattern="yyyy-MM-dd"/></td>
                    <td class="action-buttons">
                        <a href="${pageContext.request.contextPath}/employee/view?id=${emp.id}" class="btn-view">查看</a>
                        <a href="${pageContext.request.contextPath}/employee/edit?id=${emp.id}" class="btn-edit">编辑</a>
                        <a href="${pageContext.request.contextPath}/employee/delete?id=${emp.id}" class="btn-delete" onclick="return confirm('确定要删除吗？')">删除</a>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${empty pageDTO.list}">
                <tr>
                    <td colspan="7" class="no-data">没有找到匹配的员工信息</td>
                </tr>
            </c:if>
            </tbody>
        </table>

        <!-- 分页 -->
        <div class="pagination">
            <c:if test="${pageDTO.pageNum > 1}">
                <a href="${pageContext.request.contextPath}/employee?pageNum=1&name=${queryDTO.name}&department=${queryDTO.department}&position=${queryDTO.position}">首页</a>
                <a href="${pageContext.request.contextPath}/employee?pageNum=${pageDTO.pageNum-1}&name=${queryDTO.name}&department=${queryDTO.department}&position=${queryDTO.position}">上一页</a>
            </c:if>

            <span>第 ${pageDTO.pageNum} 页 / 共 ${pageDTO.pages} 页</span>

            <c:if test="${pageDTO.pageNum < pageDTO.pages}">
                <a href="${pageContext.request.contextPath}/employee?pageNum=${pageDTO.pageNum+1}&name=${queryDTO.name}&department=${queryDTO.department}&position=${queryDTO.position}">下一页</a>
                <a href="${pageContext.request.contextPath}/employee?pageNum=${pageDTO.pages}&name=${queryDTO.name}&department=${queryDTO.department}&position=${queryDTO.position}">末页</a>
            </c:if>
        </div>
    </div>
</main>
</body>
<script src="js/script.js"></script>
</html>